import pyodbc
from openai import OpenAI
import json

client = OpenAI(api_key="sk-SrY9j09edoTgsnJwiccTzlTJd13G0rnhumzuWTmV0RtFCWDu", base_url="http://chatapi.littlewheat.com/v1")
with open('analysis\shangwu.txt','r',encoding='utf-8') as fp:
    text=fp.read()
    text=text.split('。')
    print(len(text))


# import json

# with open('D:\\VSCODE\\python\\object\\dachuang\\MODLE\\ans.json','r',encoding='utf-8') as fp:
#     text=fp.read()

# text=json.loads(text)
# with open('ans2.json','w',encoding='utf-8') as fa:
#     fa.write(json.dumps(text,ensure_ascii=False))
# access_db_path = r"D:\xzh\Documents\data\DB01.accdb"  # 请将此替换为你的 Access 数据库文件路径
# conn_str = (
#     r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
#     rf'DBQ={access_db_path};'
# )
# conn = pyodbc.connect(conn_str)
# cursor = conn.cursor()

# # 假设 Access 数据库中有一个名为 Words 的表，包含一列名为 Word 的词汇
# query = "SELECT 分级, 三级分类 FROM 语法总表v2"
# try:
#     cursor.execute(query)
#     grammar = {'一级语法':['方位名词'],'二级语法':[],'三级语法':[],'四级语法':[],'五级语法':[],'六级语法':[],'七——九级语法':[]}
#     temp='方位名词'
#     for row in cursor.fetchall():
#         # access_words_dict[row[0]] = row[1]  # 以词汇为键，引标号为值存储在字典中
#         # print(row)
#         if row[1] == temp :
#             continue
#         else:
#             grammar[row[0]].append(row[1])
#             temp = row[1]
# except pyodbc.Error as db_error:
#     print(f"执行 SQL 查询时出错: {db_error}")


# sentence="王丽：（对大妈）您好！大妈：你好！王丽：(对大爷)您好！大爷：你好！王丽：再见！大爷、大妈：再见！（王丽见到邻居家10岁的小姑娘和8岁的小男孩儿。"

# system_prompt='''
# 我将提供给你一个句子sentence,和一个json格式的语法等级数据grammar,这个数据中有一级,二级,三级,四级,五级,六级,七——九级这七个语法等级包含的语法,请你根据这个句子的语法,给出这七个语法等级的数量,最终结果只以json形式输出
# 例如sentence中包含1个一级语法,两个二级语法,一个三级语法,那么你应该输出
# {
# "一级": 1,
# "二级": 2,
# "三级": 1,
# "四级": 0,
# "五级": 0,
# "六级": 0,
# "七——九级": 0,
# }'''

# user_prompt=f'''
# sentence:
# {sentence}
# grammar:
# {grammar}
# 请你根据sentence的语法,给出一级,二级,三级,四级,五级,六级,七——九级这七个语法等级的数量,最终结果只以json形式输出
# '''


# messages = [{"role": "system", "content": system_prompt},
#     {"role": "user", "content": user_prompt}]

# response = client.chat.completions.create(
#     model="gpt-4o-mini",
#     messages=messages,
#     max_tokens=8192,
#     response_format={
#         'type': 'json_object'
#     } 
# )
# # with open('ans.json','w',encoding='utf-8') as fp:
#     # fp.write(response.choices[0].message.content)
# un_ans=json.loads(response.choices[0].message.content)
# print(un_ans)